package com.javasm.crm.controller.goodController;

import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.BrandCriteria;
import com.javasm.crm.domin.criteria.GoodsCriteria;
import com.javasm.crm.domin.criteria.ProductCriteria;
import com.javasm.crm.domin.criteria.TypeCriteria;
import com.javasm.crm.domin.entity.productEntity.*;
import com.javasm.crm.service.productservice.*;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/12-17:27
 * @desp:
 * @since:
 */
@RestController
@RequestMapping("product")
public class ProductController {
    @Autowired
    ProductVoService productVoService;
    @Autowired
    ColorService colorService;
    @Autowired
    BrandService brandService;
    @Autowired
    TypeService typeService;
    @Autowired
    GoodsVoService goodsVoService;
    @Autowired
    GoodsInfoService goodsInfoService;
    @Autowired
    GoodsSecondService goodsSecondService;
    @Autowired
    TypeBrandVoService typeBrandVoService;
    @GetMapping("getyyy")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<ProductVo>> getCriyyy( ProductCriteria productCriteria) {
        PageResult<ProductVo> productVoPageResult = productVoService.searchPageByCriteria(productCriteria);
        return AxiosResult.success(productVoPageResult);
    }
    @GetMapping("typeBrandVoService")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<TypeBrandVo>> typeBrandVoService( TypeCriteria typeCriteria) {
        PageResult<TypeBrandVo> productVoPageResult = typeBrandVoService.searchPageByCriteria(typeCriteria);
        return AxiosResult.success(productVoPageResult);
    }
    @GetMapping("GoodsVo")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<GoodsVo>> getGoodsVo( GoodsCriteria goodsCriteria) {
        PageResult<GoodsVo> goodsVoPageResult = goodsVoService.searchPageByCriteria(goodsCriteria);
        return AxiosResult.success(goodsVoPageResult);
    }
    @GetMapping("GoodsbrandCri")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<Brand>> getbrand(BrandCriteria brandCriteria) {
        PageResult<Brand> brandPageResult = brandService.searchPageByCriteria(brandCriteria);
        return AxiosResult.success(brandPageResult);
    }
    @GetMapping("GoodstypeCri")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<PageResult<Type>> GoodstypeCri(TypeCriteria typeCriteria) {
        PageResult<Type> typePageResult = typeService.searchPageByCriteria(typeCriteria);
        return AxiosResult.success(typePageResult);
    }
    @GetMapping("getcolor")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<List<Color>> getColors(){
        List<Color> allColors = colorService.getAllColors();
        return AxiosResult.success(allColors);
    }
    @GetMapping("getbrand")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<List<Brand>> getBrands(){
        List<Brand> allBrands = brandService.getAllBrands();
        return AxiosResult.success(allBrands);
    }
    @GetMapping("gettype")
    @ApiOperation(value = "条件查询", notes = "条件查询")
    public AxiosResult<List<Type>> getTypes(){
        List<Type> allTypes = typeService.getAllTypes();
        return AxiosResult.success(allTypes);
    }


    @DeleteMapping("branddelete/{brandId}")
    @ApiOperation(value = "删除学生", notes = "删除学生")
    public AxiosResult<Integer> branddelete(@PathVariable Integer brandId) {
        int i = brandService.deleteById(brandId);
        return BaseController.toAxiosResult(i);
    }
    @DeleteMapping("delete/{goodId}")
    @ApiOperation(value = "删除学生", notes = "删除学生")
    public AxiosResult<Integer> productDelete(@PathVariable Integer goodId) {
        int deleteById = goodsVoService.deleteById(goodId);
        return BaseController.toAxiosResult(deleteById);
    }
    @DeleteMapping("deleteTypeById/{goodId}")
    @ApiOperation(value = "删除学生", notes = "删除学生")
    public AxiosResult<Integer> deleteTypeById(@PathVariable Integer goodId) {
        int delete = typeService.delete(goodId);
        return BaseController.toAxiosResult(delete);
    }

    @PostMapping("save")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> save(@RequestBody ProductVo productVo) {
//        int save = studentService.save(ProductVo);
        int save = productVoService.saveProduct(productVo);
        return BaseController.toAxiosResult(save);
    }

    @PostMapping("addTypes")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> addTypes(@RequestBody Type type) {
//        int save = studentService.save(ProductVo);
        int add = typeService.add(type);
        return BaseController.toAxiosResult(add);
    }
    @PostMapping("addBrand")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> addBrand(@RequestBody Brand brand) {
//        int save = productVoService.saveProduct(productVo);
        int i = brandService.addBrand(brand);
        return BaseController.toAxiosResult(i);
    }
    @GetMapping("findbyid/{goodId}")
    public AxiosResult<GoodsInfo> findByid(@PathVariable Integer goodId){
        GoodsInfo byId = goodsInfoService.findById(goodId);
        return AxiosResult.success(byId);
    }
    @PutMapping("edit")
    @ApiOperation(value = "更新学生", notes = "更新学生")
    public AxiosResult<Integer> edit(@RequestBody GoodsInfo goodsInfo) {
//        int update = studentService.updateById(student);
        int update = goodsInfoService.update(goodsInfo);
        return BaseController.toAxiosResult(update);
    }

    @PutMapping("editBrand")
    @ApiOperation(value = "更新学生", notes = "更新学生")
    public AxiosResult<Integer> editBrand(@RequestBody Brand brand) {
//        int update = goodsInfoService.update(goodsInfo);
        int update = brandService.update(brand);
        return BaseController.toAxiosResult(update);
    }

    @PutMapping("updateTypeForBrand")
    @ApiOperation(value = "更新学生", notes = "更新学生")
    public AxiosResult<Integer> updateTypeForBrand(@RequestBody Type type) {
//        int update = goodsInfoService.update(goodsInfo);
        int update = typeService.update(type);
        return BaseController.toAxiosResult(update);
    }
    @PostMapping("add")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> add(@RequestBody GoodsInfo goodsInfo) {
//        int save = productVoService.saveProduct(productVo);
        int add = goodsInfoService.add(goodsInfo);
        return BaseController.toAxiosResult(add);
    }

    @PostMapping("addSecond")
    @ApiOperation(value = "添加学生", notes = "添加学生")
    public AxiosResult<Integer> addSecond(@RequestBody GoodsSecond goodsSecond) {
        int add = goodsSecondService.add(goodsSecond);
        return BaseController.toAxiosResult(add);
    }
}
